package com.nbsaas.boot.config;

import org.yaml.snakeyaml.Yaml;

import java.io.IOException;
import java.io.InputStream;

public class ConfigLoader {

    // 使用 ClassLoader 加载配置文件
    public static Config loadConfig(String fileName) throws IOException {
        Yaml yaml = new Yaml();

        // 使用 ClassLoader 加载资源
        try (InputStream inputStream = ConfigLoader.class.getClassLoader().getResourceAsStream(fileName)) {
            if (inputStream == null) {
                throw new IOException("YAML configuration file not found: " + fileName);
            }
            return yaml.loadAs(inputStream, Config.class);
        }
    }
}
